package com.hongxun.design.utils;

import android.app.Activity;
import android.os.Bundle;

import com.hongxun.design.MyApp;
import com.hongxun.design.R;
import com.hongxun.design.activitys.FaceSendAndReceiveActivity;
import com.hongxun.design.activitys.RegeditActivity;
import com.hongxun.design.activitys.SelectProjectActivity;
import com.hongxun.design.bean.SearchProjectBean;
import com.hongxun.design.bean.photopassbean.SystemTypeBean;
import com.hongxun.design.constant.Constant;
import com.hongxun.design.mytools.IntentToActivity;
import com.hongxun.design.mytools.MString;
import com.hongxun.design.mytools.MyLog;
import com.hongxun.design.ui.dialogstyle.MyDialog;
import com.hongxun.design.ui.myiossheet.ActionSheet;
import com.hongxun.design.utils.fastjson.FastJsonUtil;
import com.hongxun.design.utils.projectdatautil.DataFactory;
import com.zbar.lib.CaptureActivity;

import java.util.ArrayList;
import java.util.List;



/**
 * Created by zerdoor_pc on 2016/6/12.
 */
public class ActionSheetUtil {
    public static void openSheet(final Activity activity, List<SystemTypeBean> data, final String json) {
        if (data == null || data.size() == 0) return;
        List<String> name = new ArrayList<>();
        final List<String> code = new ArrayList<>();
        final List<String> code_id = new ArrayList<>();
        name.add("选择阶段");
        code.add("0");
        code_id.add("0");
        for (SystemTypeBean s : data) {
            name.add(s.getTypename());
            code.add(s.getTypecode());
            code_id.add(s.code);
        }
        ActionSheet menuView = new ActionSheet(activity);
        menuView.setCancelButtonTitle("取消");// before add items
        menuView.addItems(name);
        menuView.setItemClickListener(new ActionSheet.MenuItemClickListener() {
            @Override
            public void onItemClick(int itemPosition) {
                if (itemPosition == 0) return;
                MyLog.L(MString.SUCCESSED + "点击=="+json);
               // Bundle bundle = new Bundle();
               // bundle.putString(MString.stage_id, code.get(itemPosition));
                //bundle.putString(MString.stage, code_id.get(itemPosition));
                //bundle.putString(MString.PATH, json);
               // bundle.putString(MString.TYPE, MString.MAP);
                SearchProjectBean searchProjectBean = FastJsonUtil.JsonToGetSearchProject(json);
                MyApp.currProject.setSearchBean(searchProjectBean, itemPosition - 1);

                DataFactory.ProjectClickMap(activity, MyApp.currProject);//点击判断函数
                //IntentToActivity.intent(activity, ProjectMapActivity.class);
            }
        });
        menuView.setCancelableOnTouchMenuOutside(true);
        menuView.showMenu();
    }


    public static void openSheetForRetrievePassword(final Activity activity, List<SystemTypeBean> data) {
        activity.setTheme(R.style.ActionSheetStyleIOS7);
        if (data == null || data.size() == 0) return;
        List<String> name = new ArrayList<>();
        final List<String> code = new ArrayList<>();
        name.add("选择方式");
        code.add("0");
        for (SystemTypeBean s : data) {
            name.add(s.getTypename());
            code.add(s.getTypecode());
        }
        ActionSheet menuView = new ActionSheet(activity);
        menuView.setCancelButtonTitle("取消");// before add items
        menuView.addItems(name);
        menuView.setItemClickListener(new ActionSheet.MenuItemClickListener() {
            @Override
            public void onItemClick(int itemPosition) {
                if (itemPosition == 0) return;
                MyLog.L(MString.SUCCESSED + "点击");
                if (MString.SECRET.equals(code.get(itemPosition))) {
                    MyDialog.dialogForInputUser(activity);
                } else {
                    Bundle bundle = new Bundle();
                    bundle.putString(MString.TYPE, code.get(itemPosition));
                    IntentToActivity.intent(activity, RegeditActivity.class, bundle);
                }

            }
        });
        menuView.setCancelableOnTouchMenuOutside(true);
        menuView.showMenu();
    }


    public static void openSheetForChoiceSend(final Activity activity, String... title) {
        activity.setTheme(R.style.ActionSheetStyleIOS7);
        if (title == null || title.length == 0) return;


        final ActionSheet menuView = new ActionSheet(activity);
        menuView.setCancelButtonTitle("取消");// before add items
        menuView.setFirstIsTiTle(false);
        menuView.addItems(title);
        menuView.setItemClickListener(new ActionSheet.MenuItemClickListener() {
            @Override
            public void onItemClick(int itemPosition) {

                if (itemPosition==0) {//发送文件
                    Bundle bundle= new Bundle();
                    bundle.putInt(MString.TYPE, Constant.FACELOAD);
                    IntentToActivity.intent(activity, SelectProjectActivity.class, bundle);
                } else {
                    //发送二维码
                    Bundle bundle= new Bundle();
                    bundle.putInt(MString.TYPE, Constant.CODELOAD);
                    IntentToActivity.intent(activity,SelectProjectActivity.class,bundle);
                }
                menuView.dismiss();
            }
        });
        menuView.setCancelableOnTouchMenuOutside(true);
        menuView.showMenu();
    }


    public static void openSheetForChoiceReceive(final Activity activity, String... title) {
        activity.setTheme(R.style.ActionSheetStyleIOS7);
        if (title == null || title.length == 0) return;


        final ActionSheet menuView = new ActionSheet(activity);
        menuView.setCancelButtonTitle("取消");// before add items
        menuView.setFirstIsTiTle(false);
        menuView.addItems(title);
        menuView.setItemClickListener(new ActionSheet.MenuItemClickListener() {
            @Override
            public void onItemClick(int itemPosition) {

                if (itemPosition==0) {//接收文件
                    Bundle bundle= new Bundle();
                    bundle.putInt(MString.TYPE, Constant.receive);
                    IntentToActivity.intent(activity,FaceSendAndReceiveActivity.class,bundle);
                } else {
                    //接收二维码
                    Bundle bun = new Bundle();
                    bun.putString(MString.TITLE, MString.Scan);
                    bun.putString(MString.TYPE, MString.Scanproject);
                    IntentToActivity.intent(activity, CaptureActivity.class, bun);
                }
                menuView.dismiss();
            }
        });
        menuView.setCancelableOnTouchMenuOutside(true);
        menuView.showMenu();
    }
}
